import { ref } from 'vue';

function useDistribution() {
    const { proxy } = getCurrentInstance() as ComponentInternalInstance;

    const distributionVisible = ref(false);
    const distributionObj = ref<any>();

    /** 打开弹窗 */
    const handleReinsurancePolicy = (row: any) => {
        if (row.acceptId) {
            proxy?.$modal.msgWarning('已经有设计师接单，无法分单');
            return
        }

        distributionObj.value = row;
        distributionVisible.value = true;
    };

    /** 提交成功的操作 */
    const handleSubmit = (result: boolean, fun: Function) => {
        if (result) {
            fun();
        };
    };

    /** 关闭弹窗 */
    const handleCloseAdd = () => {
        distributionObj.value = {};
        distributionVisible.value = false;
    };

    return {
        distributionVisible,
        distributionObj,
        handleReinsurancePolicy,
        handleSubmit,
        handleCloseAdd
    };
};

export default useDistribution;